//
//  HJVersionListController.m
//  KaiChat
//
//  Created by lx on 2023/10/19.
//

#import "HJVersionListController.h"
#import "HJVersionListCell.h"
#import "HJMinePresent.h"
#import "HJVersionDetailController.h"

@interface HJVersionListController ()

@property (nonatomic, strong) NSArray *datas;

@end

@implementation HJVersionListController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationBar.title = @"Kai Fresh";
    
    [self.tableView registerClass:HJVersionListCell.class forCellReuseIdentifier:@"HJVersionListCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 70;
    self.tableView.backgroundColor = UIColor.whiteColor;
    self.tableView.showsVerticalScrollIndicator = NO;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(KNavBarHight);
        make.bottom.offset(0);
    }];
    
    [self loadData];
}
 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HJVersionListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HJVersionListCell" forIndexPath:indexPath];
    cell.dict = self.datas[indexPath.row];;
   return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    HJVersionDetailController *versionDetailController = [[HJVersionDetailController alloc] init];
    versionDetailController.dict = self.datas[indexPath.row];;
    [self.navigationController pushViewController:versionDetailController];
}
 

- (void)loadData {
    [HJMinePresent loadVersionListWithPageIndex:1 pageSize:20 complete:^(NSArray * _Nullable data, NSError * _Nullable error) {
        self.datas = data;
        [self.tableView reloadData];
    }];
}


@end
